import 'package:async_button/async_button.dart';
import 'package:flutter/material.dart';
import 'package:flutter_deer/res/resources.dart';
import 'package:flutter_deer/util/theme_utils.dart';

class TextLabelItem extends StatelessWidget {

  TextLabelItem({
    super.key,
    required this.title,
    this.hintText = '',
    this.actionText = '',
    this.onPressed
  });

  final String title;
  final String hintText;
  final String actionText;
  final Function(AsyncBtnStatesController controller)? onPressed;
  AsyncBtnStatesController btnStateController = AsyncBtnStatesController();

  @override
  Widget build(BuildContext context) {
    final Row child = Row(
      children: <Widget>[
        Text(title),
        Gaps.hGap16,
        Expanded(
          child: Text(
            hintText.isEmpty ? '' : hintText
          ),
        ),
        Visibility(visible: actionText!='',child: AsyncTextBtn(asyncBtnStatesController:btnStateController,child: Text(actionText),loadingStyle: AsyncBtnStateStyle(
          style: TextButton.styleFrom(
            foregroundColor: context.isDark?Colours.dark_app_main:Colours.app_main,
          ),
          widget: SizedBox.square(
            dimension: 24,
            child: CircularProgressIndicator(
              color: context.isDark?Colours.dark_app_main:Colours.app_main,
            ),
          ),
        ),onPressed: () async {btnStateController.update(AsyncBtnState.loading);onPressed!.call(btnStateController);}),),
        Gaps.hGap16
      ],
    );
    
    return Container(
      height: 50.0,
      margin: const EdgeInsets.only(left: 16.0),
      width: double.infinity,
      decoration: BoxDecoration(
        border: Border(
          bottom: Divider.createBorderSide(context, width: 0.6),
        ),
      ),
      child: child,
    );
  }

}
